﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DOMINIO;
using BL;
using System.Xml.Linq;
using System.Web.Profile;


namespace Presentacion
{
    public partial class CrearUsuario : System.Web.UI.Page
    {

        //public static String nombre;
        EmpleadoBL empBL;


        protected void Page_Load(object sender, EventArgs e)
        {

            empBL = new EmpleadoBL();

        }

        protected void btnBuscarByDNI_Click(object sender, EventArgs e)
        {
            TextBox txtDNI = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtDni") as TextBox;
            TextBox txtPersonal = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtPersonal") as TextBox;
            HiddenField hiCodEmpleado = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("hiCodEmpleado") as HiddenField;

            Empleado empleado = empBL.BuscarEmpleadoPorDni(Int32.Parse(txtDNI.Text));

            txtPersonal.Text = empleado.NombreCompleto;
            hiCodEmpleado.Value = empleado.Dni;
        }

        protected void btnBuscar_Click(object sender, EventArgs e)
        {
            TextBox txtUserName = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName") as TextBox;

            if (txtUserName != null)
            {
                lblUserName.Text = txtUserName.Text;
            }

        }

        protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            TextBox txtDNI = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtDni") as TextBox;
            TextBox txtPersonal = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtPersonal") as TextBox;
            HiddenField hiCodEmpleado = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("hiCodEmpleado") as HiddenField;

            ProfileBase p = (ProfileBase)ProfileBase.Create(CreateUserWizard1.UserName, true);


            p.SetPropertyValue("CodEmpleado", hiCodEmpleado.Value);
            p.SetPropertyValue("DNI", hiCodEmpleado.Value);
            p.SetPropertyValue("Empleado", txtPersonal.Text);
            p.Save();
        }


    }
}